<template>
  <div id="news-detail">
    <h2>{{ article.title }}</h2>
    <h4>{{ article.create_time }} | {{ article.name }}</h4>
    <section v-html="article.content"></section>
  </div>
</template>

<script>
  export default {
    name: "item-news-detail",
    data() {
      return {
        /**
         * 根据接口数据格式：{
         *    title: xxx // 标题
         *    create_time: xxx // 创建时间
         *    name: xxx // 资讯类别
         *    content: xxx // 内容
         * }
         */
        article: {

        }
      }
    },
    methods: {
      loadDetail() {
        this.$http.post({
          api: this.$api.NEWS_DETAIL,
          params: {
            id: this.$route.params.id
          },
          success: function (res) {
            if (Object.keys(res.data.data).length !== 0) {
              this.article = res.data.data;
            }
          }.bind(this)
        })
      }
    },
    created() {
      this.loadDetail();
    },
    watch: {
      '$route': 'loadDetail'
    }
  }
</script>

<style lang="scss">

  #news-detail {
    background: $white;

    $side-padding: 1.2rem;

    >h2 {
      padding: 1.4rem $side-padding 0;
      font-size: 1.8rem;
      font-weight: bold;
      line-height: 2.8rem;
      color: #333;
      word-wrap: break-word;
      margin-bottom: 0.7rem;
    }

    >h4 {
      font-size: 1.2rem;
      color: #999;
      padding: 0 $side-padding;
      margin-bottom: 1.2rem;
    }

    >section {
      padding: 0 $side-padding;
      font-size: 1.6rem;
      text-indent: 2.8rem;
      color: #333;

      >* {
        margin-bottom: 1rem;
      }

      >p {
        width: $size-as-parent;

        >img {
          width: $size-as-parent;
          height: auto;
        }
      }
    }
  }
</style>
